package com.example.trader.service;


import com.example.trader.common.Result;
import com.example.trader.entity.Order;
import com.example.trader.mapper.OrderManagerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderManagerService {

    @Autowired
    private OrderManagerMapper orderManagerMapper;

    public List<Order> getOrderList() {
        List<Order> orderList = orderManagerMapper.getOrderList();
        return orderList;
    }

    public Result deleteOrderById(Integer orderId) {
        int count = orderManagerMapper.deleteOrderById(orderId);
        if (count == 0) {
            return Result.error("400", "删除失败!");
        }
        return Result.success("删除成功!");

    }

    public List<Order> getOrderById(Integer orderId) {
        List<Order> orderList = orderManagerMapper.getOrderById(orderId);
        return orderList;
    }

    public Result updateOrderStatus(Order order) {

      int count=  orderManagerMapper.updateOrderStatus(order);
      if(count==0){
          return Result.error("400","修改状态失败!");
      }
      return Result.success("修改状态成功!");
    }
}
